<template>
  <div class="rating">
    <ul class="score">
      <li>
        <p>5.0</p>
        <p>综合评价</p>
        <p>高于周边商家96%</p>
      </li>
      <li>
        <p>
          服务态度
          <van-rate v-model="value" readonly void-icon="star" :size="16" color="#ff9a04" void-color="#eee" allow-half />
          <span>{{value}}</span>
        </p>
        <p>
          菜品质量
          <van-rate v-model="value" readonly void-icon="star" :size="16" color="#ff9a04" void-color="#eee" allow-half />
          <span>{{value}}</span>
        </p>
        <p>
          送达时间
          <span>20分钟</span>
        </p>
      </li>
    </ul>
    <div class="rating-content">
      <van-tabs type="card" @change="onChange" v-model="ractive" color="#ffc300" title-active-color="#000">
        <van-tab :title="'全部'+agentrating.length"></van-tab>
        <van-tab :title="'满意'+dataLength"></van-tab>
        <van-tab :title="'不满意'+(agentrating.length-dataLength)"></van-tab>
      </van-tabs>
      <ul>
        <li v-for="(item,index) in ratingsData" :key="index">
          <template>
            <img :src="item.avatar">
            <div>
              <p>
                <span>{{item.username}}</span>
                <span>{{item.rateTime}}</span>
              </p>
              <p>
                <van-rate v-model="item.score" readonly void-icon="star" :size="14" color="#ff9a04" void-color="#eee" allow-half />
                <span>{{item.deliveryTime}}分钟送达</span>
              </p>
              <p>
                {{item.text}}
              </p>
              <p>
                <van-icon name="good-job" color="#ffc300" />
                <em>
                  <span v-for="(value,index) in item.recommend" :key="index">{{value}}</span>
                </em>
              </p>
            </div>
          </template>
        </li>
      </ul>
    </div>
  </div>
</template>

<script lang="ts">
import { Component, Vue } from "vue-property-decorator";
import { getRatings_api } from "@/apis/rating.js";
import moment from "moment";
import Car from "@/components/Car.vue";

@Component({
  components: {
    Car,
  },
})
export default class extends Vue {
  ractive = 0;
  // 评分
  value = 4.5;
  ratingsData = [];
  agentrating = [];

  async created() {
    let res = await getRatings_api();
    //console.log(res.data);
    //快速修复出来的
    res.data.data.forEach((item: { rateTime: moment.MomentInput }) => {
      item.rateTime = moment(item.rateTime).format("YYYY-MM-DD HH:mm:ss");
    });
    this.agentrating = res.data.data;
    this.ratingsData = this.agentrating;
    //console.log(this.ratingsData);
  }
  //计算属性，得到满意数据，不满意数据的长度
  get dataLength() {
    return this.agentrating.filter((item: any) => {
      return item.rateType === 0;
    }).length;
  }

  onChange(index: any) {
    //改变时，进行筛选
    switch (index) {
      case 0:
        this.ratingsData = this.agentrating;
        break;
      case 1:
        this.ratingsData = this.agentrating.filter((item: any) => {
          return item.rateType === 0;
        });
        break;
      case 2:
        this.ratingsData = this.agentrating.filter((item: any) => {
          return item.rateType === 1;
        });
        break;
    }
  }
}
</script>

<style lang="scss" scoped>
.rating {
  background-color: #f4f5f7;
  height: 100%;
}
.score {
  display: flex;
  padding: 20px 0;
  color: #000;
  margin-bottom: 20px;
  background-color: #fff;
  li:first-child {
    width: 35%;
    text-align: center;
    border-right: 1px solid #eeeeee;
    p:first-child {
      color: #ffc300;
      font-weight: bold;
      font-size: 22px;
    }
    p:nth-child(2) {
      line-height: 36px;
      font-size: 16px;
    }
    p:last-child {
      color: #999;
      font-size: 12px;
    }
  }
  li:last-child {
    width: 60%;
    padding-left: 15px;
    p {
      line-height: 26px;
      font-size: 15px;
      span {
        color: #ffc300;
      }
      .van-rate {
        margin: 0 4px;
      }
    }
    p:last-child {
      span {
        color: #999;
        margin-left: 4px;
      }
    }
  }
}
.rating-content {
  background-color: #fff;
  padding: 20px 0;
  display: flex;
  flex-direction: column;
  height: 100%;
  .van-tabs {
    padding-bottom: 10px;
  }
  ul {
    flex: 1;
    overflow-y: scroll;
    li {
      display: flex;
      margin: 0 10px;
      padding: 20px 0;
      border-bottom: 1px solid #f4f4f4;
      img {
        width: 50px;
        height: 50px;
        border-radius: 50%;
        margin-right: 10px;
      }
      div {
        flex: 1;
        p:first-child {
          font-size: 14px;
          display: flex;
          justify-content: space-between;
          span:first-child {
            font-weight: bold;
          }
          span:last-child {
            color: #999999;
          }
        }
        p:nth-child(2) {
          line-height: 30px;
          span:last-child {
            margin-left: 10px;
            color: #999999;
            font-size: 12px;
          }
        }
        p:nth-child(3) {
          font-size: 15px;
          line-height: 20px;
        }
        p:last-child {
          display: flex;
          margin-top: 4px;
          span {
            display: inline-block;
            font-size: 12px;
            border: 1px solid #bbbbbb;
            color: #bbb;
            border-radius: 2px;
            padding: 3px;
            margin: 0 2px 4px;
            font-style: normal;
          }
        }
      }
    }
  }
}
</style>